#####################################################################################
##### Gov 2001 Replication                   ########################################
#### Table 3            [Negative Binomial]  ########################################
#####################################################################################

require(stargazer)
require(foreign)
require(gridExtra)
library(ggplot2)
library(survival)
library(readstata13)
library(xtable)
require(MASS)
require(plm)
require(DataCombine)
library(zoo)
library(OutlierDC)
library(reshape2)

rm(list = ls())

### Change this to your directory
setwd("/Users/andrewleber/Documents/Harvard Study/2016 Spring/GOV 2001/Final Write-Up/Table 3")

#####################################################################################
### Replication of Negative Binomial Model: Table 3
### Table 3 (p. 780), using country dummies
#####################################################################################
table <- read.dta13("HRV_APSR_Tables_3_&_4.dta")

###Exclude observations if democracy = 1

T3_fe.data <- table[which(table$democracy==0), ]

#Create contestation variables lagged by one year

lag_GenStrikes <- slide(T3_fe.data, Var = "GenStrikes", GroupVar = "wdicode",
                        slideBy = -1)

lag_Riots <- slide(T3_fe.data, Var = "Riots", GroupVar = "wdicode",
                   slideBy = -1)

lag_AntiGovDem <- slide(T3_fe.data, Var = "AntiGovDem", GroupVar = "wdicode",
                        slideBy = -1)

lag_Revolutions <- slide(T3_fe.data, Var = "Revolutions", GroupVar = "wdicode",
                         slideBy = -1)

lag_Guerilla <- slide(T3_fe.data, Var = "Guerilla", GroupVar = "wdicode",
                      slideBy = -1)

lag_Coups <- slide(T3_fe.data, Var = "Coups", GroupVar = "wdicode",
                   slideBy = -1)

lag_Assinations <- slide(T3_fe.data, Var = "Assinations", GroupVar = "wdicode",
                         slideBy = -1)

lag_GovCrises <- slide(T3_fe.data, Var = "GovCrises", GroupVar = "wdicode",
                       slideBy = -1)

lag_Purges <- slide(T3_fe.data, Var = "Purges", GroupVar = "wdicode",
                    slideBy = -1)

###Create control variables lagged by one year

lag_grgdpch <- slide(T3_fe.data, Var = "grgdpch", GroupVar = "wdicode",
                     slideBy = -1)

lag_transparencyindex <- slide(T3_fe.data, Var = "transparencyindex", GroupVar = "wdicode",
                               slideBy = -1)

lag_trans_growth <- slide(T3_fe.data, Var = "trans_growth", GroupVar = "wdicode",
                          slideBy = -1)

lag_rgdpch <- slide(T3_fe.data, Var = "rgdpch", GroupVar = "wdicode",
                    slideBy = -1)

lag_openk <- slide(T3_fe.data, Var = "openk", GroupVar = "wdicode",
                   slideBy = -1)

lag_lparty_alt <- slide(T3_fe.data, Var = "lparty_alt", GroupVar = "wdicode",
                        slideBy = -1)

lag_nmil <- slide(T3_fe.data, Var = "nmil", GroupVar = "wdicode",
                  slideBy = -1)

###Add lagged variables to data series

fulldata <- cbind(lag_Assinations$`Assinations-1`, lag_GenStrikes$`GenStrikes-1`,
                  lag_GovCrises$`GovCrises-1`, lag_Purges$`Purges-1`,
                  lag_Riots$`Riots-1`, lag_AntiGovDem$`AntiGovDem-1`,
                  lag_Coups$`Coups-1`, lag_Guerilla$`Guerilla-1`,
                  lag_transparencyindex$`transparencyindex-1`,
                  lag_grgdpch$`grgdpch-1`, lag_trans_growth$`trans_growth-1`,
                  lag_rgdpch$`rgdpch-1`, lag_openk$`openk-1`,
                  lag_lparty_alt$`lparty_alt-1`, lag_nmil$`nmil-1`, 
                  lag_Revolutions$`Revolutions-1`, T3_fe.data)


####################################################################################
### Function to trim all zeros
####################################################################################

TrimZero<-function(data, count, trim){
  index<-unique(data[,trim])
  
  ### Creates separate indices for 
  ### #, sum of counts per ID
  check1<-c()
  check2<-c()
  
  for(i in 1:length(index)){
    check1[i]<-length(which(data[,trim]==index[i]))
    check2[i]<-sum(data[which(data[,trim]==index[i]), count], na.rm=TRUE)
  }
  
  print(index[which(check1==1)])
  print(index[which(check2==0)])
  print(table(check2))
  print(cbind(index, check2))
  
  
  remove<-unique(c(index[which(check1==1)], index[which(check2==0)]))
  
  ### Trims and returns data
  r<-which(data[,trim]%in%remove)
  
  data<-data[-r,]
  return(data)
}

#########################################################################################################
## Strikes 
Strike3<-data.frame(TrimZero(fulldata, "GenStrikes", "ccode"))
names(Strike3)[1:16]<-c("lag_Assassinations", "lag_Strikes",
                        "lag_Crises", "lag_Purges", "lag_Riots",
                        "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                        "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                        "lag_open", "lag_party", "lag_mil",
                        "lag_Revolutions")

# Remove entries to match State code procedures
Strike3<-Strike3[-which(Strike3$ccode%in%c(652, 700)),]

col_1.3 <- glm.nb(GenStrikes ~ lag_Strikes + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(ccode),
                  data = Strike3)

summary(col_1.3)

## Riots
Riot3<-data.frame(TrimZero(fulldata, "Riots", "ccode"))
names(Riot3)[1:16]<-c("lag_Assassinations", "lag_Strikes",
                      "lag_Crises", "lag_Purges", "lag_Riots",
                      "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                      "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                      "lag_open", "lag_party", "lag_mil",
                      "lag_Revolutions")

# Remove entries to match State code procedures
Riot3<-Riot3[-which(Riot3$ccode%in%c(145, 790, 652, 640)),]

col_2.3 <- glm.nb(Riots ~ lag_Riots + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(ccode),
                  data = Riot3)

summary(col_2.3)

## Demonstrations
Dem3<-data.frame(TrimZero(fulldata, "AntiGovDem", "ccode"))
names(Dem3)[1:16]<-c("lag_Assassinations", "lag_Strikes",
                     "lag_Crises", "lag_Purges", "lag_Riots",
                     "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                     "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                     "lag_open", "lag_party", "lag_mil",
                     "lag_Revolutions")

# Remove entries to match State code procedures
Dem3<-Dem3[-which(Dem3$ccode%in%c(652, 432, 145)),]

col_3.3 <- glm.nb(AntiGovDem ~ lag_AntiGovDem + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(ccode),
                  data = Dem3)

summary(col_3.3)

# 145, 432, 652

## Revolutions
Rev3<-data.frame(TrimZero(fulldata, "Revolutions", "ccode"))
names(Rev3)[1:16]<-c("lag_Assassinations", "lag_Strikes",
                     "lag_Crises", "lag_Purges", "lag_Riots",
                     "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                     "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                     "lag_open", "lag_party", "lag_mil",
                     "lag_Revolutions")

# Remove entries to match State code procedures
Rev3<-Rev3[-which(Rev3$ccode%in%c(145)),]

col_4.3 <- glm.nb(Revolutions ~ lag_Revolutions + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(ccode),
                  data = Rev3)

summary(col_4.3)
# 4 off...

## guerilla
G3<-data.frame(TrimZero(fulldata, "Guerilla", "ccode"))
names(G3)[1:16]<-c("lag_Assassinations", "lag_Strikes",
                   "lag_Crises", "lag_Purges", "lag_Riots",
                   "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                   "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                   "lag_open", "lag_party", "lag_mil",
                   "lag_Revolutions")

col_5.3 <- glm.nb(Guerilla ~ lag_Guerilla  + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(ccode),
                  data = G3)

summary(col_5.3)
# 3 off...

## Coups
Coup3<-data.frame(TrimZero(fulldata, "Coups", "ccode"))
names(Coup3)[1:16]<-c("lag_Assassinations", "lag_Strikes",
                      "lag_Crises", "lag_Purges", "lag_Riots",
                      "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                      "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                      "lag_open", "lag_party", "lag_mil",
                      "lag_Revolutions")

# Remove entries to match State code procedures
Coup3<-Coup3[-which(Coup3$ccode%in%c(145)),]

col_6.3 <- glm.nb(Coups ~ lag_Coups + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(ccode),
                  data = Coup3)

summary(col_6.3)

## Assassination
A3<-data.frame(TrimZero(fulldata, "Assinations", "ccode"))
names(A3)[1:16]<-c("lag_Assassinations", "lag_Strikes",
                   "lag_Crises", "lag_Purges", "lag_Riots",
                   "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                   "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                   "lag_open", "lag_party", "lag_mil",
                   "lag_Revolutions")

# Remove entries to match State code procedures
A3<-A3[-which(A3$ccode%in%c(145, 438, 652)),]

col_7.3 <- glm.nb(Assinations ~ lag_Assassinations + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(ccode),
                  data = A3)

summary(col_7.3)

stargazer(col_1.3,col_2.3,col_3.3,col_4.3,col_5.3,col_6.3,col_7.3)

#####################################################################################
### Replication of Negative Binomial Model: Table 3
### Table 3 (p. 780), extended data
#####################################################################################
table2 <- read.dta13("HRV_Banks data for Tables 3 and 4 (1980-2007).dta")

###Exclude observations if democracy = 1

T3_fe.data2 <- table2[which(table2$democracy==0), ]

#Create contestation variables lagged by one year

lag_GenStrikes <- slide(T3_fe.data2, Var = "GenStrikes", GroupVar = "iso3n",
                        slideBy = -1)

lag_Riots <- slide(T3_fe.data2, Var = "Riots", GroupVar = "iso3n",
                   slideBy = -1)

lag_AntiGovDem <- slide(T3_fe.data2, Var = "AntiGovDem", GroupVar = "iso3n",
                        slideBy = -1)

lag_Revolutions <- slide(T3_fe.data2, Var = "Revolutions", GroupVar = "iso3n",
                         slideBy = -1)

lag_Guerilla <- slide(T3_fe.data2, Var = "Guerilla", GroupVar = "iso3n",
                      slideBy = -1)

lag_Coups <- slide(T3_fe.data2, Var = "Coups", GroupVar = "iso3n",
                   slideBy = -1)

lag_Assinations <- slide(T3_fe.data2, Var = "Assinations", GroupVar = "iso3n",
                         slideBy = -1)

###Create control variables lagged by one year

lag_grgdpch <- slide(T3_fe.data2, Var = "grgdpch", GroupVar = "iso3n",
                     slideBy = -1)

lag_transparencyindex <- slide(T3_fe.data2, Var = "transparencyindex", GroupVar = "iso3n",
                               slideBy = -1)

lag_trans_growth <- slide(T3_fe.data2, Var = "trans_growth", GroupVar = "iso3n",
                          slideBy = -1)

lag_rgdpch <- slide(T3_fe.data2, Var = "rgdpch", GroupVar = "iso3n",
                    slideBy = -1)

lag_openk <- slide(T3_fe.data2, Var = "openk", GroupVar = "iso3n",
                   slideBy = -1)

lag_lparty_alt <- slide(T3_fe.data2, Var = "lparty_alt", GroupVar = "iso3n",
                        slideBy = -1)

lag_nmil <- slide(T3_fe.data2, Var = "nmil", GroupVar = "iso3n",
                  slideBy = -1)

###Add lagged variables to data2 series

fulldata2 <- cbind(lag_Assinations$`Assinations-1`, lag_GenStrikes$`GenStrikes-1`,
                   lag_Riots$`Riots-1`, lag_AntiGovDem$`AntiGovDem-1`,
                   lag_Coups$`Coups-1`, lag_Guerilla$`Guerilla-1`,
                   lag_transparencyindex$`transparencyindex-1`,
                   lag_grgdpch$`grgdpch-1`, lag_trans_growth$`trans_growth-1`,
                   lag_rgdpch$`rgdpch-1`, lag_openk$`openk-1`,
                   lag_lparty_alt$`lparty_alt-1`, lag_nmil$`nmil-1`, 
                   lag_Revolutions$`Revolutions-1`, T3_fe.data2)


####################################################################################
### Function to trim all zeros
####################################################################################

#########################################################################################################
## Strikes
Strike3<-data.frame(TrimZero(fulldata2, "GenStrikes", "iso3n"))
names(Strike3)[1:14]<-c("lag_Assassinations", "lag_Strikes",
                        "lag_Riots",
                        "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                        "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                        "lag_open", "lag_party", "lag_mil",
                        "lag_Revolutions")
head(Strike3)

# Remove entries to match State code procedures
Strike3<-Strike3[-which(Strike3$iso3n%in%c(4, 108, 218, 760)),]

col_1.3 <- glm.nb(GenStrikes ~ lag_Strikes + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(iso3n),
                  data = Strike3)

summary(col_1.3)

## Riots
Riot3<-data.frame(TrimZero(fulldata2, "Riots", "iso3n"))
names(Riot3)[1:14]<-c("lag_Assassinations", "lag_Strikes",
                      "lag_Riots",
                      "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                      "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                      "lag_open", "lag_party", "lag_mil",
                      "lag_Revolutions")

# Remove entries to match State code procedures
Riot3<-Riot3[-which(Riot3$iso3n%in%c(68, 288, 340, 760)),]

col_2.3 <- glm.nb(Riots ~ lag_Riots + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(iso3n),
                  data = Riot3)

summary(col_2.3)

## Demonstrations
Dem3<-data.frame(TrimZero(fulldata2, "AntiGovDem", "iso3n"))
names(Dem3)[1:14]<-c("lag_Assassinations", "lag_Strikes",
                     "lag_Riots",
                     "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                     "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                     "lag_open", "lag_party", "lag_mil",
                     "lag_Revolutions")

# Remove entries to match State code procedures
Dem3<-Dem3[-which(Dem3$iso3n%in%c(108, 218, 466, 784)),]

Dem3.1<-Dem3[which(complete.cases(Dem3)),]

col_3.3 <- glm.nb(AntiGovDem ~ lag_AntiGovDem + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(iso3n),
                  data = Dem3.1)

summary(col_3.3)

## Revolutions
Rev3<-data.frame(TrimZero(fulldata2, "Revolutions", "iso3n"))
names(Rev3)[1:14]<-c("lag_Assassinations", "lag_Strikes",
                     "lag_Riots",
                     "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                     "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                     "lag_open", "lag_party", "lag_mil",
                     "lag_Revolutions")

# Remove entries to match State code procedures
Rev3<-Rev3[-which(Rev3$iso3n%in%c(68, 218, 410, 764, 792)),]

col_4.3 <- glm.nb(Revolutions ~ lag_Revolutions + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(iso3n),
                  data = Rev3)

summary(col_4.3)
# 4 off...

## guerilla
G3<-data.frame(TrimZero(fulldata2, "Guerilla", "iso3n"))
names(G3)[1:14]<-c("lag_Assassinations", "lag_Strikes",
                   "lag_Riots",
                   "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                   "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                   "lag_open", "lag_party", "lag_mil",
                   "lag_Revolutions")

# Remove entries to match State code procedures
G3<-G3[-which(G3$iso3n%in%c(50, 178, 792)),]

col_5.3 <- glm.nb(Guerilla ~ lag_Guerilla  + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(iso3n),
                  data = G3)

summary(col_5.3)
# 3 off...


## Coups
Coup3<-data.frame(TrimZero(fulldata2, "Coups", "iso3n"))
names(Coup3)[1:14]<-c("lag_Assassinations", "lag_Strikes",
                      "lag_Riots",
                      "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                      "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                      "lag_open", "lag_party", "lag_mil",
                      "lag_Revolutions")

# Remove entries to match State code procedures
Coup3<-Coup3[-which(Coup3$iso3n%in%c(68, 178, 218, 288, 586, 792)),]

col_6.3 <- glm.nb(Coups ~ lag_Coups + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(iso3n),
                  data = Coup3)

summary(col_6.3)

## Assassination
A3<-data.frame(TrimZero(fulldata2, "Assinations", "iso3n"))
names(A3)[1:14]<-c("lag_Assassinations", "lag_Strikes",
                   "lag_Riots",
                   "lag_AntiGovDem", "lag_Coups", "lag_Guerilla",
                   "lag_transparency", "lag_Growth", "lag_TXG", "lag_GDP",
                   "lag_open", "lag_party", "lag_mil",
                   "lag_Revolutions")

# Remove entries to match State code procedures
A3<-A3[-which(A3$iso3n%in%c(68, 792, 764, 624, 218)),]

col_7.3 <- glm.nb(Assinations ~ lag_Assassinations + lag_transparency + lag_Growth +
                    lag_TXG+lag_GDP+lag_open+lag_party+lag_mil+
                    oil+t+t2+t3+factor(iso3n),
                  data = A3)

summary(col_7.3)


stargazer(col_1.3, col_2.3, col_3.3, col_4.3, col_5.3, col_6.3, col_7.3)

############################################################
### Use estimates from Stata code to produce coefficient plots
############################################################
pe <- c(.649988, # Point estimates for Table 3, Original Dataset
        .1926166,
        .3316333,
        .0232337,
        .0151358,
        -.1850993,
        .0639577)


ub <- c(.649988 + 1.96*.2449295 ,# Upper bounds for Table 3, Original Dataset
        .1926166 + 1.96*.0934026 ,
        .3316333 + 1.96*.0842206  , 
        .0232337 + 1.96*.0558937 ,
        .0151358 + 1.96*.0620216,
        -.1850993 + 1.96*.2356848,
        .0639577 + 1.96*.111273)


lb <- c(.649988 - 1.96*.2449295 ,# Lower bounds for Table 3, Original Dataset
        .1926166 - 1.96*.0934026 ,
        .3316333 - 1.96*.0842206,
        .0232337 - 1.96*.0558937 ,
        .0151358 - 1.96*.0620216, 
        -.1850993 - 1.96*.2356848,
        .0639577 - 1.96*.111273)


label <- c("General Strikes", "Riots", "Demonstrations",
           "Revolutions", "Guerrilla", "Coups",
           "Assassinations")


df <- data.frame(pe, ub, lb, label)


pdf("T3_Coefplot.pdf", width = 7, height = 4)
par(mar=c(5,7,5,5))

# dots
plot(x = 1:nrow(df),
     y = df$pe,
     ylim = range(df$ub, df$lb),
     pch = 16,
     col = "blue",
     axes = F,
     xlab= "Type of Unrest",
     ylab="Effect of Transparency",
     main="Transparency and Type of Unrest")

for(i in 1:nrow(df)) {
  lines(c(i, i), c(df$ub[i], df$lb[i]),
        col = "blue", lwd = 1)
}


axis(2) # x-axis
axis(1, 1:nrow(df), labels = df$label, las = 1, cex.axis=0.6) # y axis

abline(h=0, col="red", lty=2, lwd=1)
dev.off()

###############################################################
## Generate a coefficient plot for original, extended data
###############################################################

pe2 <- c(.2223769, # Point Estimates for Table 3, Extended Dataset
         .0284217,
         .0835446, 
         -.0486299,
         -.0256214,
         -.2293236,
         .0297945)


ub2 <- c(.2223769 + 1.96*.180952, # Upper bounds for Table 3, Extended Dataset
         .0284217 + 1.96*.0674993,
         .0835446  + 1.96*.0537061, 
         -.0486299 + 1.96*.0489652,
         -.0256214 + 1.96*.052612,
         -.2293236 + 1.96*.2141787,
         .0297945 + 1.96*.0731228)


lb2 <- c(.2223769 - 1.96*.180952, # Upper bounds for Table 3, Original Dataset
         .0284217 - 1.96*.0674993,
         .0835446  - 1.96*.0537061, 
         -.0486299 - 1.96*.0489652,
         -.0256214 - 1.96*.052612,
         -.2293236 - 1.96*.2141787,
         .0297945 - 1.96*.0731228)


label2 <- c("General Strikes", "Riots", "Demonstrations",
            "Revolutions", "Guerrilla", "Coups",
            "Assassinations")


df2 <- data.frame(pe2, ub2, lb2, label2)

# Plot comparisons of original, expanded dataset
pdf("T3_Compared.pdf", width = 7, height = 8)
par(par(oma=c(0,0,2,0)), mar=c(5,7,5,5))
layout(matrix(c(1,2), 2, 1, byrow = TRUE))

plot(x = 1:nrow(df),
     y = df$pe,
     ylim = range(df$ub, df$lb),
     pch = 16,
     col = "blue",
     axes = F,
     xlab= "Type of Unrest",
     ylab="Effect of Transparency",
     main="Original Dataset (1980-1999)")

for(i in 1:nrow(df)) {
  lines(c(i, i), c(df$ub[i], df$lb[i]),
        col = "blue", lwd = 1)
}


axis(2) # x-axis
axis(1, 1:nrow(df), labels = df$label, las = 1, cex.axis=0.6) # y axis

abline(h=0, col="red", lty=2, lwd=1)

# dots
plot(x = 1:nrow(df2),
     y = df2$pe,
     ylim = range(df2$ub, df2$lb),
     pch = 16,
     col = "blue",
     axes = F,
     xlab= "Type of Unrest",
     ylab="Effect of Transparency",
     main="Extended Dataset (1980-2007)")

for(i in 1:nrow(df2)) {
  lines(c(i, i), c(df2$ub[i], df2$lb[i]),
        col = "blue", lwd = 1)
}


axis(2) # x-axis
axis(1, 1:nrow(df2), labels = df2$label, las = 1, cex.axis=0.6) # y axis

abline(h=0, col="red", lty=2, lwd=2)
title("Effect of Transparency on Unrest",
      outer = T, cex = 2)
dev.off()